<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>页面就是画布，可以点击画画</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        canvas{
            border: 1px solid #000;
        }
    </style>
</head>
<body>
    <canvas id="canvas" width="1280" height="600"></canvas>
    <script>
        var canvas = document.getElementById("canvas")
        var ctx = canvas.getContext("2d")
        var x  = 0,y=0
        canvas.addEventListener("mousedown",function (e) {
            x=e.offsetX
            y = e.offsetY
            ctx.moveTo(x,y)
            canvas.onmousemove = function (e) {
                x = e.offsetX
                y = e.offsetY
                console.log(x)
                ctx.lineTo(x,y)
            ctx.stroke()
            }
        })

        canvas.onmouseup = function () {
            canvas.onmousemove = null
            // ctx.fill()
//            ctx.fill('evenodd')
        }

    </script>
</body>
</html>